package com.yc.dygang;

import com.google.gson.Gson;
import com.yc.dygang.entity.Movie;
import com.yc.dygang.mapper.MovieMapper;
import com.yc.dygang.util.MyBatisHelper;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "selectMovie", value = "/selectMovie.s")
public class SelectMovie extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            request.setCharacterEncoding("UTF-8");
            response.setCharacterEncoding("UTF-8");
            response.setContentType("text/html;charset=UTF8");
        try (SqlSession session = MyBatisHelper.getSession()){
            MovieMapper mapper = session.getMapper(MovieMapper.class);
            List<Movie> movielist = mapper.selectMovielist();
            String json = new Gson().toJson(movielist);
            response.getWriter().append(json);
        }
    }
}